package com.tin.triper.Helper;

import java.util.List;

import android.content.Context;
import android.location.Location;

import com.google.android.maps.GeoPoint;
import com.tin.triper.R;
import com.tin.triper.Data.TripPoint;

public class Formating {
	public static String converseToTime(int time, Context context) {
		int days = time / 1000 / 3600 / 24;
		int hours = time / 1000 / 3600 - days * 24;
		int minutes = time / 1000 / 60 - days * 24 - hours * 60;
		String toReturn = "";
		if (days > 0) {
			toReturn += days + " " + context.getString(R.string.date_day) + " ";
		}
		if (hours > 0) {
			toReturn += hours + " " + context.getString(R.string.date_hour) + " ";
		}
		if (minutes > 0) {
			toReturn += minutes + " " + context.getString(R.string.date_minute);
		}
		if (toReturn.length() == 0)
			return "0 " + context.getString(R.string.date_minute);
		return toReturn;
	}
	public static String countSpeed(List<TripPoint> pointList,int currentPoint) {
		if(currentPoint==0)
			return "0 km/h";
		else{
			float distance;
			float time;
			Location loc1= new Location("none");
			loc1.setLatitude((double)pointList.get(currentPoint-1).getLatitudeE6()/1e6);
			loc1.setLongitude((double)pointList.get(currentPoint-1).getLongitudeE6()/1e6);
			Location loc2= new Location("none");
			loc2.setLatitude((double)pointList.get(currentPoint).getLatitudeE6()/1e6);
			loc2.setLongitude((double)pointList.get(currentPoint).getLongitudeE6()/1e6);
			distance=loc2.distanceTo(loc1)/1000;
			time=pointList.get(currentPoint).time-pointList.get(currentPoint-1).time;
			
			time=time/1000/3600;
			float toReturn=distance/time;
			if(toReturn < 1)
				return toReturn*1000+" m/h";
			else
				return toReturn+" km/h";
		}
	}
}
